//
//  BaseHttpUtility.h
//  YiMiSchool
//
//  Created by 吴凯强 on 2021/1/7.
//  Copyright © 2021 yimilan. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AFNetworking/AFNetworking.h>
@class HYBaseResModel, HYNetworkRequest;

NS_ASSUME_NONNULL_BEGIN

// MARK: 全局类型 typedef
/**
 
 */
typedef enum : NSUInteger {
    HYNetworkRequestMethodPost = 0,
    HYNetworkRequestMethodGet
} HYNetworkRequestMethod;

typedef void(^HYNetworkSuccessBlock)(HYBaseResModel *model);
typedef void(^HYNetworkFailureBlock)(NSInteger errorCode, NSString *errorInfo);

typedef NSString HYServerURL;


// MARK: HYNetwork

@protocol HYNetworkDataSource <NSObject>
/// 必须实现  慎用  只在AppDelegate+networkMonitoring类中实现使用
@required
- (NSDictionary *)commonParams;
- (NSString *)gatewayAppkey;
- (NSString *)gatewayToken;
- (NSString *)cookieHeaderValue;
- (NSString *)ymlKey;
- (NSString *)requestToken;
- (NSString *)userId;
- (AFNetworkReachabilityStatus)networkState;

- (HYNetworkRequest *)refreshToken:(NSString *)oldToken
                       withSuccess:(HYNetworkSuccessBlock)success
                           failure:(HYNetworkFailureBlock)failure;

- (void)performLogoutWithHUDMsg:(NSString *)msg;

@end

@interface HYNetwork : NSObject

@property (nonatomic, strong, readonly) AFHTTPSessionManager *sessionManager;
@property (nonatomic, strong, readonly) NSMutableDictionary *reloadRequests;

@property (nonatomic, weak) id<HYNetworkDataSource> dataSource;

+ (instancetype)sharedInstance;
- (HYNetworkRequest *)refreshToken:(NSString *)token;
- (void)addReloadRequest:(HYNetworkRequest *)request;

@end

// MARK: YMLAFJSONResponseSerializer

@interface YMLAFJSONResponseSerializer : AFJSONResponseSerializer

@end

// MARK: FOUNDATION_EXPORT 全局函数 & 变量

FOUNDATION_EXPORT HYServerURL * const HYServerURLGateway(void);
FOUNDATION_EXPORT HYServerURL * const HYServerURLYWMainApi(void);
FOUNDATION_EXPORT HYServerURL * const HYServerURLParentApi(void);
FOUNDATION_EXPORT HYServerURL * const HYServerURLSap(void);
FOUNDATION_EXPORT HYServerURL * const HYServerURLWxH5(void);

FOUNDATION_EXPORT NSInteger const kHYNetworkDefaultTimeout;
FOUNDATION_EXPORT NSInteger const kHYNetworkMainHomeTimeoutInterval;

/// 登录状态被踢的通知
FOUNDATION_EXPORT NSString * const YiMiYueDuNotificationReLoginStatusChanged;
NS_ASSUME_NONNULL_END
